﻿namespace GameLib.Games.Components
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using GameLib.Games.Util;

    public class ModMessageHandler<T> : AbstractModMatcherHandler<T> where T : IMod
    {

        public override ModMatcherHandlerAction Handle(IModMatcher matcher, T mod)
        {
            ModMatcherHandlerEventArgs eventArgs = new ModMatcherHandlerEventArgs(mod);

            OnBeforeHandleEvent(eventArgs);

            if (eventArgs.Action == null) {
                eventArgs.Action = ModMatcherHandlerAction.DoNothing;
                this.displayMessage(matcher, mod);
            }

            eventArgs.Handled = true;
            OnAfterHandleEvent(eventArgs);

            return eventArgs.Action;
        }

        private DialogResult displayMessage(IModMatcher matcher, T mod)
        {
            if (!string.IsNullOrEmpty(matcher.Message))
            {
                string message = "";
                if (mod == null)
                {
                    message += "The following message is in regards to the mod " + matcher.Owner.Name + "(" + matcher.Owner.Id + "):";
                }
                else
                {
                    message += "The following message is in regards to the mods " + matcher.Owner.Name + "(" + matcher.Owner.Id + ") and " + mod.Name + "(" + mod.Id + "):";
                }

                message += "\n\n" + matcher.Message;

                string title = matcher.Owner.Name + " - Message";

                return MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return DialogResult.OK;
        }
    }
}
